//
//  DiscountImageTableViewCell.m
//  FairyDream
//
//  Created by dllo on 15/8/26.
//  Copyright (c) 2015年 dreams. All rights reserved.
//

#import "DiscountImageTableViewCell.h"
#import "DiscountCustomCollectionViewCell.h"
#import "UIImageView+WebCache.h"
@interface DiscountImageTableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collectionView;

@end

@implementation DiscountImageTableViewCell

- (void)dealloc
{
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.fourImagesArray = [NSMutableArray array];
        [self createCollectionView];
    }
    return self;
}

- (void)createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    
    layout.itemSize = CGSizeMake(180, 200);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 375, 400) collectionViewLayout:layout];
    
    [_collectionView registerClass:[DiscountCustomCollectionViewCell class] forCellWithReuseIdentifier:@"four"];
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    [self addSubview:_collectionView];
    [layout release];
    [_collectionView release];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _fourImagesArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DiscountCustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"four" forIndexPath:indexPath];
    if (_fourImagesArray.count != 0) {
        NSDictionary *dic = [_fourImagesArray objectAtIndex:indexPath.item];
        [cell.imageViews sd_setImageWithURL:[dic objectForKey:@"photo"] placeholderImage:nil];
        cell.titleLable.text = [NSString stringWithFormat:@"%@", [dic objectForKey:@"title"]];
        cell.discountLable.text = [NSString stringWithFormat:@"%@", [dic objectForKey:@"priceoff"]];
        // 转码
        NSString *str = [dic objectForKey:@"price"];
        str = [str stringByReplacingOccurrencesOfString:@"<em>" withString:@""];
        str = [str stringByReplacingOccurrencesOfString:@"</em>" withString:@""];
        cell.priceLable.text = [NSString stringWithFormat:@"%@", str];
    }
    
    return cell;
}







@end
